<?php
namespace App\Http\Repository;

use App\Http\Controllers\common\BaseController;
use App\Models\Consult;
use Illuminate\Support\Facades\Redis;

class InformationRepository extends BaseController
{
    /**
     * @return false|string
     * Su ang
     * 资讯开发接口
     */
    public static function informatonShow()
    {
        $data = consult::where('status',config('setting.system.status'))->orderBy('issue_time',config('setting.system.order'))-> get()->toArray();
        return self::retJson('200','成功',$data);

    }

    /**
     * @param $id
     * @return false|string
     * Su ang
     * 资讯详情接口
     */
    public static function listIndex($id)
    {

        $data = Redis::get($id);
        if (empty($data)){
            $content =  consult::where('id',$id)->get()->toarray();
            $content = json_encode($content);
            consult::where('id',$id)->increment('read');
            Redis::setex($id,60*60*24,$content);
            $data = json_decode($content,true);
            return self::retJson('200','成功',$data);
        }else{
            $data = Redis::get($id);
            consult::where('id',$id)->increment('read');
            $data = json_decode($data,true);
            return self::retJson('200','成功',$data);
        }
    }
}
